﻿using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi.DtSer.ExtDS
{
    /// <summary>
    /// 部署外部扩展服务
    /// </summary>
    [CPPEI.WebApi.AuthPostAction("ExtDS", "Publish", "1.0")]
    public class PublishAction : BaseAction<PublishParams, PublishResult>
    {
        protected override ActionResult<PublishResult> OnExecute(ActionContext context,
            SysParameters sysParameters,
            PublishParams opParams)
        {
            SER.ExtDSService dtSerService = new SER.ExtDSService();
            ServiceResult serResult = dtSerService.Publish(opParams.AssemblyId, opParams.AssemblyName, opParams.AssemblyVersion, opParams.TypeSettings);

            if(serResult.IsSuccess)
            {
                PublishResult result = new PublishResult();
                return new ActionResult<PublishResult>(result);
            }
            else
            {
                return new ActionResult<PublishResult>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message, null);
            }
        }
    }

    public class PublishParams
    {
        public Guid AssemblyId { get; set; }

        public string AssemblyName { get; set; }

        public string AssemblyVersion { get; set; }

        /// <summary>
        /// id,name,description,id,name,description
        /// </summary>
        public string TypeSettings { get; set; }
    }

    public class PublishResult
    {
    }
}
